<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Adapting Functions</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Phoenix 3.2.0">
<link rel="up" href="../function.html" title="Function">
<link rel="prev" href="../function.html" title="Function">
<link rel="next" href="../operator.html" title="Operator">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../operator.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="phoenix.modules.function.adapting_functions"></a><a class="link" href="adapting_functions.html" title="Adapting Functions">Adapting
        Functions</a>
</h4></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary">BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY</a></span></dt>
<dt><span class="section"><a href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function">BOOST_PHOENIX_ADAPT_FUNCTION</a></span></dt>
<dt><span class="section"><a href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary">BOOST_PHOENIX_ADAPT_CALLABLE_NULLARY</a></span></dt>
<dt><span class="section"><a href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable">BOOST_PHOENIX_ADAPT_CALLABLE</a></span></dt>
</dl></div>
<p>
          If you want to adapt already existing functions or function objects it
          will become a repetetive task. Therefor the following boilerplate macros
          are provided to help you adapt already exsiting functions, thus reducing
          the need to <a class="link" href="../bind.html" title="Bind">phoenix.modules.bind</a>
          functions.
        </p>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary"></a><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary" title="BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY">BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY</a>
</h5></div></div></div>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.h0"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.description"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.description">Description</a>
          </h6>
<p>
            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY</span></code>
            is a macro that can be used to generate all the necessary boilerplate
            to make an arbitrary nullary function a lazy function.
          </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              These macros generate no global objects. The resulting lazy functions
              are real functions that create the lazy function expression object
            </p></td></tr>
</table></div>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.h1"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.synopsis"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY</span><span class="special">(</span>
    <span class="identifier">RETURN_TYPE</span>
  <span class="special">,</span> <span class="identifier">LAZY_FUNCTION</span>
  <span class="special">,</span> <span class="identifier">FUNCTION</span>
<span class="special">)</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.h2"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.semantics"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.semantics">Semantics</a>
          </h6>
<p>
            The above macro generates all necessary code to have a nullary lazy function
            <code class="computeroutput"><span class="identifier">LAZY_FUNCTION</span></code> which calls
            the nullary <code class="computeroutput"><span class="identifier">FUNCTION</span></code>
            that has the return type <code class="computeroutput"><span class="identifier">RETURN_TYPE</span></code>
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.h3"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.header"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.header">Header</a>
          </h6>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">function</span><span class="special">/</span><span class="identifier">adapt_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.h4"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.example"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function_nullary.example">Example</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">demo</span>
<span class="special">{</span>
    <span class="keyword">int</span> <span class="identifier">foo</span><span class="special">()</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="number">42</span><span class="special">;</span>
    <span class="special">}</span>
<span class="special">}</span>

<span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">demo</span><span class="special">::</span><span class="identifier">foo</span><span class="special">)</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">_1</span><span class="special">;</span>

    <span class="identifier">assert</span><span class="special">((</span><span class="identifier">_1</span> <span class="special">+</span> <span class="identifier">foo</span><span class="special">())(</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="number">43</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function"></a><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function" title="BOOST_PHOENIX_ADAPT_FUNCTION">BOOST_PHOENIX_ADAPT_FUNCTION</a>
</h5></div></div></div>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.h0"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.description"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.description">Description</a>
          </h6>
<p>
            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION</span></code>
            is a macro that can be used to generate all the necessary boilerplate
            to make an arbitrary function a lazy function.
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.h1"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.synopsis"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION</span><span class="special">(</span>
    <span class="identifier">RETURN_TYPE</span>
  <span class="special">,</span> <span class="identifier">LAZY_FUNCTION</span>
  <span class="special">,</span> <span class="identifier">FUNCTION</span>
  <span class="special">,</span> <span class="identifier">FUNCTION_ARITY</span>
<span class="special">)</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.h2"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.semantics"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.semantics">Semantics</a>
          </h6>
<p>
            The above macro generates all necessary code to have a lazy function
            <code class="computeroutput"><span class="identifier">LAZY_FUNCTION</span></code> which calls
            <code class="computeroutput"><span class="identifier">FUNCTION</span></code> that has the
            return type <code class="computeroutput"><span class="identifier">RETURN_TYPE</span></code>
            with <code class="computeroutput"><span class="identifier">FUNCTION_ARITY</span></code> number
            of arguments.
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.h3"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.header"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.header">Header</a>
          </h6>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">function</span><span class="special">/</span><span class="identifier">adapt_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.h4"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.example"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_function.example">Example</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">demo</span>
<span class="special">{</span>
    <span class="keyword">int</span> <span class="identifier">plus</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
    <span class="identifier">T</span>
    <span class="identifier">plus</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">c</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span> <span class="special">+</span> <span class="identifier">c</span><span class="special">;</span>
    <span class="special">}</span>
<span class="special">}</span>

<span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">plus</span><span class="special">,</span> <span class="identifier">demo</span><span class="special">::</span><span class="identifier">plus</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span>

<span class="identifier">BOOST_PHOENIX_ADAPT_FUNCTION</span><span class="special">(</span>
    <span class="keyword">typename</span> <span class="identifier">remove_reference</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">&gt;::</span><span class="identifier">type</span>
  <span class="special">,</span> <span class="identifier">plus</span>
  <span class="special">,</span> <span class="identifier">demo</span><span class="special">::</span><span class="identifier">plus</span>
  <span class="special">,</span> <span class="number">3</span>
<span class="special">)</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">arg_names</span><span class="special">::</span><span class="identifier">arg1</span><span class="special">;</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">arg_names</span><span class="special">::</span><span class="identifier">arg2</span><span class="special">;</span>

    <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">123</span><span class="special">;</span>
    <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">256</span><span class="special">;</span>

    <span class="identifier">assert</span><span class="special">(</span><span class="identifier">plus</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">)(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">);</span>
    <span class="identifier">assert</span><span class="special">(</span><span class="identifier">plus</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="number">3</span><span class="special">)(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">+</span><span class="number">3</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary"></a><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary" title="BOOST_PHOENIX_ADAPT_CALLABLE_NULLARY">BOOST_PHOENIX_ADAPT_CALLABLE_NULLARY</a>
</h5></div></div></div>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.h0"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.description"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.description">Description</a>
          </h6>
<p>
            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE_NULLARY</span></code>
            is a macro that can be used to generate all the necessary boilerplate
            to make an arbitrary nullary function object a lazy function.
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.h1"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.synopsis"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE_NULLARY</span><span class="special">(</span>
    <span class="identifier">LAZY_FUNCTION</span>
  <span class="special">,</span> <span class="identifier">CALLABLE</span>
<span class="special">)</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.h2"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.semantics"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.semantics">Semantics</a>
          </h6>
<p>
            The above macro generates all necessary code to create <code class="computeroutput"><span class="identifier">LAZY_FUNCTION</span></code> which creates a lazy
            function object that represents a nullary call to <code class="computeroutput"><span class="identifier">CALLABLE</span></code>.
            The return type is specified by <code class="computeroutput"><span class="identifier">CALLABLE</span></code>
            conforming to the <a href="http://www.boost.org/doc/libs/release/libs/utility/utility.htm#result_of" target="_top">Boost.Result
            Of</a> protocol.
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.h3"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.header"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.header">Header</a>
          </h6>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">function</span><span class="special">/</span><span class="identifier">adapt_callable</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.h4"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.example"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable_nullary.example">Example</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">demo</span>
<span class="special">{</span>
    <span class="keyword">struct</span> <span class="identifier">foo</span>
    <span class="special">{</span>
        <span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">result_type</span><span class="special">;</span>

        <span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()()</span> <span class="keyword">const</span>
        <span class="special">{</span>
            <span class="keyword">return</span> <span class="number">42</span><span class="special">;</span>
        <span class="special">}</span>
    <span class="special">}</span>
<span class="special">}</span>

<span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE_NULLARY</span><span class="special">(</span><span class="identifier">foo</span><span class="special">,</span> <span class="identifier">demo</span><span class="special">::</span><span class="identifier">foo</span><span class="special">)</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">_1</span><span class="special">;</span>

    <span class="identifier">assert</span><span class="special">((</span><span class="identifier">_1</span> <span class="special">+</span> <span class="identifier">foo</span><span class="special">())(</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="number">43</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable"></a><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable" title="BOOST_PHOENIX_ADAPT_CALLABLE">BOOST_PHOENIX_ADAPT_CALLABLE</a>
</h5></div></div></div>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.h0"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.description"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.description">Description</a>
          </h6>
<p>
            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE</span></code>
            is a macro that can be used to generate all the necessary boilerplate
            to make an arbitrary function object a lazy function.
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.h1"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.synopsis"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE</span><span class="special">(</span>
    <span class="identifier">LAZY_FUNCTION</span>
  <span class="special">,</span> <span class="identifier">FUNCTION_NAME</span>
  <span class="special">,</span> <span class="identifier">FUNCTION_ARITY</span>
<span class="special">)</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.h2"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.semantics"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.semantics">Semantics</a>
          </h6>
<p>
            The above macro generates all necessary code to create <code class="computeroutput"><span class="identifier">LAZY_FUNCTION</span></code> which creates a lazy
            function object that represents a call to <code class="computeroutput"><span class="identifier">CALLABLE</span></code>
            with <code class="computeroutput"><span class="identifier">FUNCTION_ARITY</span></code> arguments.
            The return type is specified by <code class="computeroutput"><span class="identifier">CALLABLE</span></code>
            conforming to the <a href="http://www.boost.org/doc/libs/release/libs/utility/utility.htm#result_of" target="_top">Boost.Result
            Of</a> protocol.
          </p>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.h3"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.header"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.header">Header</a>
          </h6>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">function</span><span class="special">/</span><span class="identifier">adapt_callable</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<h6>
<a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.h4"></a>
            <span><a name="phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.example"></a></span><a class="link" href="adapting_functions.html#phoenix.modules.function.adapting_functions.boost_phoenix_adapt_callable.example">Example</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">demo</span>
<span class="special">{</span>
    <span class="keyword">struct</span> <span class="identifier">plus</span>
    <span class="special">{</span>
        <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Sig</span><span class="special">&gt;</span>
        <span class="keyword">struct</span> <span class="identifier">result</span><span class="special">;</span>

        <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">This</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span><span class="special">&gt;</span>
        <span class="keyword">struct</span> <span class="identifier">result</span><span class="special">&lt;</span><span class="identifier">This</span><span class="special">(</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">)&gt;</span>
            <span class="special">:</span> <span class="identifier">remove_reference</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">&gt;</span>
        <span class="special">{};</span>

        <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">This</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A2</span><span class="special">&gt;</span>
        <span class="keyword">struct</span> <span class="identifier">result</span><span class="special">&lt;</span><span class="identifier">This</span><span class="special">(</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">)&gt;</span>
            <span class="special">:</span> <span class="identifier">remove_reference</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">&gt;</span>
        <span class="special">{};</span>

        <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span><span class="special">&gt;</span>
        <span class="identifier">A0</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">A0</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">)</span> <span class="keyword">const</span>
        <span class="special">{</span>
            <span class="keyword">return</span> <span class="identifier">a0</span> <span class="special">+</span> <span class="identifier">a1</span><span class="special">;</span>
        <span class="special">}</span>

        <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A2</span><span class="special">&gt;</span>
        <span class="identifier">A0</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">A0</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">A2</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a2</span><span class="special">)</span> <span class="keyword">const</span>
        <span class="special">{</span>
            <span class="keyword">return</span> <span class="identifier">a0</span> <span class="special">+</span> <span class="identifier">a1</span> <span class="special">+</span> <span class="identifier">a2</span><span class="special">;</span>
        <span class="special">}</span>
    <span class="special">};</span>
<span class="special">}</span>

<span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE</span><span class="special">(</span><span class="identifier">plus</span><span class="special">,</span> <span class="identifier">demo</span><span class="special">::</span><span class="identifier">plus</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span>

<span class="identifier">BOOST_PHOENIX_ADAPT_CALLABLE</span><span class="special">(</span><span class="identifier">plus</span><span class="special">,</span> <span class="identifier">demo</span><span class="special">::</span><span class="identifier">plus</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">arg_names</span><span class="special">::</span><span class="identifier">arg1</span><span class="special">;</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">arg_names</span><span class="special">::</span><span class="identifier">arg2</span><span class="special">;</span>

    <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">123</span><span class="special">;</span>
    <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">256</span><span class="special">;</span>

    <span class="identifier">assert</span><span class="special">(</span><span class="identifier">plus</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">)(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">);</span>
    <span class="identifier">assert</span><span class="special">(</span><span class="identifier">plus</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">,</span> <span class="identifier">arg2</span><span class="special">,</span> <span class="number">3</span><span class="special">)(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">+</span><span class="number">3</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2010, 2014, 2015 Joel de Guzman, Dan Marsden, Thomas
      Heller, John Fletcher<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../operator.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
